package com.lb.shopguide.ui.dialog;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.lb.baselib.base.DialogBase;
import com.lb.shopguide.R;

/**
 * Created by kang on 2018/1/18.
 */

public class DialogChooseChargeinType extends DialogBase implements View.OnClickListener {
    private RelativeLayout layoutAlipay;
    private RelativeLayout layoutWechatPay;
    private ImageView ivClose;

    public static DialogChooseChargeinType getDialogChooseChargeinType() {
        DialogChooseChargeinType dialogChangePayType = new DialogChooseChargeinType();
        Bundle bundle = new Bundle();
        dialogChangePayType.setArguments(bundle);
        return dialogChangePayType;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View mFragmentView = inflater.inflate(R.layout.dialog_choose_charge_in, container, false);
        initData();
        initView(mFragmentView);

//        setDialogPosition();
        bindData();
        return mFragmentView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            DisplayMetrics dm = new DisplayMetrics();
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            dialog.getWindow().setLayout((int) (dm.widthPixels * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT);
            dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        }
    }

    private void initData() {

    }

    private void initView(View view) {
        layoutAlipay = view.findViewById(R.id.layout_alipay);
        layoutWechatPay = view.findViewById(R.id.layout_wechat_pay);
        ivClose = view.findViewById(R.id.iv_close);

        initListener();
    }

    private void bindData() {

    }

    private void initListener() {
        layoutAlipay.setOnClickListener(this);
        layoutWechatPay.setOnClickListener(this);
        ivClose.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.layout_alipay:
                mOnSetChooseTypeListener.onAliPayClick();
                break;
            case R.id.layout_wechat_pay:
                mOnSetChooseTypeListener.onWechatPayClick();
                break;
            case R.id.iv_close:
                DialogChooseChargeinType.this.dismiss();
                break;
        }
    }

    public void setChooseTypeListener(OnSetChooseTypeListener listener) {
        mOnSetChooseTypeListener = listener;
    }

    public interface OnSetChooseTypeListener {
        void onAliPayClick();

        void onWechatPayClick();
    }

    private OnSetChooseTypeListener mOnSetChooseTypeListener;
}
